package com.hualude.roadsign.controller;

import com.hualude.roadsign.dto.DTRequestDto;
import com.hualude.roadsign.dto.DTResponseDto;
import com.hualude.roadsign.dto.JsonMsgDto;
import com.hualude.roadsign.service.SignalLampFaultService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by pjn on 2017/8/5.
 */
@Controller
@RequestMapping("/rds_signalLampFault")
public class SignalLampFaultController {
    @Resource
    private SignalLampFaultService signalLampFaultService;

    @RequestMapping(value = "/getLampReportFault4DT")
    @ResponseBody
    public DTResponseDto getLampReportFault4DT(DTRequestDto dtRequestDto, Integer actorId, Integer userId, Integer orgId) {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = signalLampFaultService.getLampReportFault4DT(dtRequestDto, actorId, userId, orgId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping("/updateSignalLampFault")
    @ResponseBody
    public JsonMsgDto updateSignalLampFault(Integer lampFaultId, Integer lampLevel, Integer lampType, String lampPhoto, String lampReason, Double lampMoney) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalLampFaultService.updateSignalLampFault(lampFaultId, lampLevel, lampType, lampPhoto, lampReason, lampMoney));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);

        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/deleteLampFaultByIds")
    @ResponseBody
    public JsonMsgDto deleteLampFaultByIds(String lampFaultIds) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalLampFaultService.deleteLampFaultByIds(lampFaultIds));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getLampCoordinate4Map")
    @ResponseBody
    public JsonMsgDto getLampCoordinate4Map(Integer orgId, Integer actorId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalLampFaultService.getLampCoordinate4Map(orgId, actorId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);

        }
        return jsonMsgDto;
    }

    @RequestMapping("/getLampEnergyByXY")
    @ResponseBody
    public JsonMsgDto getLampEnergyByXY(String longitude, String latitude) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalLampFaultService.getLampEnergyByXY(longitude, latitude));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);

        }
        return jsonMsgDto;
    }

    @RequestMapping("/getStartRoad")
    @ResponseBody
    public JsonMsgDto getStartRoad(String roadName, Integer actorId, Integer orgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(signalLampFaultService.getStartRoad(roadName, actorId, orgId));
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getSectionByStartRoad")
    @ResponseBody
    public JsonMsgDto getSectionByStartRoad(String roadName, Integer actorId, Integer orgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(signalLampFaultService.getSectionByStartRoad(roadName, actorId, orgId));
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }


    @RequestMapping(value = "/reportLampFault")
    @ResponseBody
    public JsonMsgDto reportLampFault(Integer signalLampId, Integer lampCreatorId, Integer lampLevel, Integer lampType,
                                      String lampPhoto, String lampReason, Double lampMoney, Integer lampOrgId, Integer lampMainOrgId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            signalLampFaultService.reportLampFault(signalLampId, lampCreatorId, lampLevel, lampType,
                    lampPhoto, lampReason, lampMoney, lampOrgId, lampMainOrgId);
            //为空是app端作判断
            jsonMsgDto.setJsonData("");
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getLampFaultIsReport")
    @ResponseBody
    public JsonMsgDto getLampFaultIsReport(Integer signalLampId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(signalLampFaultService.getLampFaultIsReport(signalLampId));
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/getLampFaultReport4DT")
    @ResponseBody
    public DTResponseDto getLampFaultReport4DT(DTRequestDto dtRequestDto, Integer actorId, Integer orgId, String signalLampStartRoad, String signalLampEndRoad) {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = signalLampFaultService.getLampFaultReport4DT(dtRequestDto, actorId, orgId, signalLampStartRoad, signalLampEndRoad);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping(value = "/getLampFaultReportList4App")
    @ResponseBody
    public JsonMsgDto getLampFaultReportList4App(Integer orgId, String actorIds, Integer faultStatus, Integer count, Integer size)
            throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalLampFaultService.getLampFaultReportList4App(orgId, actorIds, faultStatus, count, size));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }
}
